<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${pageContext.request.contextPath }/assets/jquery/jquery-1.9.1.js"></script>
</head>
<body>			
<div style="float: right;margin-right: 40%">
	    <table>
							<tr>
								<th>候选人名称</th>
								<th>票数</th>
								<th>操作</th>
							</tr>
						<c:forEach items="${results }" var="bean">
							<tr align="center">
								<td>${bean.name }</td>
								 <td>${bean.score }</td>
								<td><a href="#"  onclick ="vote('${bean.id}','${bean.name }')">投票</a></td>
							</tr>
						</c:forEach>
					</table>
					</div>
</body>
<script type="text/javascript">
function vote(id,name){
	var userId=id;
	var userName =name;
	$.ajax({
		type:"post",
		url:"${pageContext.request.contextPath}/voteAdd",
		dataType:"json",
		data:{
			userId:userId,
			userName:userName
		},
		success:function(data){
			if(data.message =='no'){
				alert("今日投票数已经用完，请明天再来!");
			}else{
				location.reload();
			}
		}
	})
}
</script>
<link rel="stylesheet"  href="${pageContext.request.contextPath }/assets/css/table.css">
</html>